home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-06-07 | 24.5 KB | 934 lines | [TEXT/KAHL] |
- ///--------------------------------------------------------------------------------------
- // Sprite.c
- //
- // Created: Tuesday, October, 1992 at 10:10:06 PM
- // By: Tony Myles
- //
- // Copyright: © 1991-93 Tony Myles, All rights reserved worldwide
- //
- // Description: implementation of the sprites
- ///--------------------------------------------------------------------------------------
-
-
- #ifndef __MEMORY__
- #include <Memory.h>
- #endif
-
- #ifndef __SPRITEWORLDUTILS__
- #include <SpriteWorldUtils.h>
- #endif
-
- #ifndef __SPRITEWORLD__
- #include <SpriteWorld.h>
- #endif
-
- #ifndef __SPRITE__
- #include <Sprite.h>
- #endif
-
- #ifndef __FRAME__
- #include <Frame.h>
- #endif
-
-
- ///--------------------------------------------------------------------------------------
- // SWCreateSprite
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL OSErr SWCreateSprite(
- SpritePtr* newSpriteP,
- void* spriteStorageP,
- short maxFrames)
- {
- OSErr err = noErr;
- SpritePtr tempSpriteP;
- Size frameArraySize;
-
- *newSpriteP = NULL;
-
- // use NewPtrClear so we don’t have to initialize everything to zero
- tempSpriteP = (SpritePtr) (spriteStorageP == NULL) ? NewPtr(sizeof(SpriteRec)) : spriteStorageP;
-
- if (tempSpriteP != NULL)
- {
- frameArraySize = (Size)(maxFrames * sizeof(FramePtr));
-
- tempSpriteP->frameArray = (FramePtr *)NewPtrClear(frameArraySize);
-
- if (tempSpriteP->frameArray != NULL)
- {
- tempSpriteP->nextSpriteP = NULL;
- tempSpriteP->prevSpriteP = NULL;
-
- // initialize drawing fields
- tempSpriteP->isVisible = true;
- tempSpriteP->needsToBeDrawn = true;
- tempSpriteP->needsToBeErased = false;
- tempSpriteP->destFrameRect.left = 0;
- tempSpriteP->destFrameRect.top = 0;
- tempSpriteP->destFrameRect.right = 0;
- tempSpriteP->destFrameRect.bottom = 0;
- tempSpriteP->oldFrameRect.left = 0;
- tempSpriteP->oldFrameRect.top = 0;
- tempSpriteP->oldFrameRect.right = 0;
- tempSpriteP->oldFrameRect.bottom = 0;
- tempSpriteP->deltaFrameRect.left = 0;
- tempSpriteP->deltaFrameRect.top = 0;
- tempSpriteP->deltaFrameRect.right = 0;
- tempSpriteP->deltaFrameRect.bottom = 0;
- tempSpriteP->screenMaskRgn = NULL;
- tempSpriteP->frameDrawProc = SWStdDrawProc;
-
- // initialize frame fields
- tempSpriteP->frameTimeTask.timeTask.tmAddr = SWTimeTask;
- tempSpriteP->frameTimeTask.timeTask.qLink = NULL;
- tempSpriteP->frameTimeTask.timeTask.qType = 0;
- tempSpriteP->frameTimeTask.timeTask.tmCount = 0;
- tempSpriteP->frameTimeTask.timeTask.tmWakeUp = 0;
- tempSpriteP->frameTimeTask.timeTask.tmReserved = 0;
- tempSpriteP->frameTimeTask.hasTaskFired = false;
- tempSpriteP->curFrameP = NULL;
- tempSpriteP->numFrames = 0;
- tempSpriteP->maxFrames = maxFrames;
- tempSpriteP->frameTimeInterval = -1;
- tempSpriteP->frameAdvance = 1;
- tempSpriteP->curFrameIndex = 0;
- tempSpriteP->firstFrameIndex = 0;
- tempSpriteP->lastFrameIndex = 0;
- tempSpriteP->frameChangeProc = NULL;
-
- // initialize movement fields
- tempSpriteP->moveTimeTask.timeTask.tmAddr = SWTimeTask;
- tempSpriteP->moveTimeTask.timeTask.qLink = NULL;
- tempSpriteP->moveTimeTask.timeTask.qType = 0;
- tempSpriteP->moveTimeTask.timeTask.tmCount = 0;
- tempSpriteP->moveTimeTask.timeTask.tmWakeUp = 0;
- tempSpriteP->moveTimeTask.timeTask.tmReserved = 0;
- tempSpriteP->moveTimeTask.hasTaskFired = true;
- tempSpriteP->moveTimeInterval = 0;
- tempSpriteP->horizMoveDelta = 0;
- tempSpriteP->vertMoveDelta = 0;
- tempSpriteP->moveBoundsRect.left = 0;
- tempSpriteP->moveBoundsRect.top = 0;
- tempSpriteP->moveBoundsRect.right = 0;
- tempSpriteP->moveBoundsRect.bottom = 0;
- tempSpriteP->spriteMoveProc = NULL;
-
- // collision detection fields
- tempSpriteP->collideRect.left = 0;
- tempSpriteP->collideRect.top = 0;
- tempSpriteP->collideRect.right = 0;
- tempSpriteP->collideRect.bottom = 0;
- tempSpriteP->spriteCollideProc = NULL;
-
- tempSpriteP->userData = 0;
-
- // insert the sprite time tasks into the time manager queue
- InsTime((QElemPtr)&tempSpriteP->moveTimeTask);
- InsTime((QElemPtr)&tempSpriteP->frameTimeTask);
-
- // the sprite has been successfully created
- *newSpriteP = tempSpriteP;
- }
- else
- {
- err = MemError();
-
- DisposePtr((Ptr)tempSpriteP);
- }
- }
- else
- {
- err = MemError();
- }
-
- return err;
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWCreateSpriteFromCIconResource
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL OSErr SWCreateSpriteFromCIconResource(
- SpritePtr* newSpriteP,
- void* spriteStorageP,
- short cIconID,
- short maxFrames,
- MaskType maskType)
- {
- OSErr err;
- SpritePtr tempSpriteP;
- FramePtr newFrameP;
- short frame;
-
- *newSpriteP = NULL;
-
- err = SWCreateSprite(&tempSpriteP, spriteStorageP, maxFrames);
-
- if (err == noErr)
- {
- for (frame = 0; frame < maxFrames; frame++)
- {
- err = SWCreateFrameFromCIconResource(&newFrameP, cIconID + frame, maskType);
-
- if (err == noErr)
- {
- err = SWAddFrame(tempSpriteP, newFrameP);
- }
-
- if (err != noErr)
- {
- SWDisposeFrame(newFrameP);
- SWDisposeSprite(tempSpriteP, true);
- break;
- }
- }
-
- if (err == noErr)
- {
- *newSpriteP = tempSpriteP;
- }
- }
-
- return err;
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWCreateSpriteFromPictResource
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL OSErr SWCreateSpriteFromPictResource(
- SpritePtr* newSpriteP,
- void* spriteStorageP,
- short pictResID,
- short maskResID,
- short maxFrames,
- MaskType maskType)
- {
- OSErr err;
- SpritePtr tempSpriteP;
- FramePtr newFrameP;
- short frame;
-
- *newSpriteP = NULL;
-
- err = SWCreateSprite(&tempSpriteP, spriteStorageP, maxFrames);
-
- if (err == noErr)
- {
- for (frame = 0; frame < maxFrames; frame++)
- {
- err = SWCreateFrameFromPictResource(&newFrameP, pictResID + frame, maskResID + frame, maskType);
-
- if (err == noErr)
- {
- err = SWAddFrame(tempSpriteP, newFrameP);
- }
-
- if (err != noErr)
- {
- SWDisposeFrame(newFrameP);
- SWDisposeSprite(tempSpriteP, true);
- break;
- }
- }
-
- if (err == noErr)
- {
- *newSpriteP = tempSpriteP;
- }
- }
-
- return err;
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWCloneSprite
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL OSErr SWCloneSprite(
- SpritePtr cloneSpriteP,
- SpritePtr* newSpriteP,
- void* spriteStorageP)
- {
- OSErr err;
- SpritePtr tempSpriteP;
- TimeTaskRec moveTimeTask, frameTimeTask;
- short frame;
-
- err = SWCreateSprite(&tempSpriteP, spriteStorageP, cloneSpriteP->maxFrames);
-
- if (err == noErr)
- {
- // save off the time tasks, these are unique to a particular sprite
- moveTimeTask = tempSpriteP->moveTimeTask;
- frameTimeTask = tempSpriteP->frameTimeTask;
-
- // copy the clone sprite into the temp sprite
- *tempSpriteP = *cloneSpriteP;
-
- // restore the time tasks
- tempSpriteP->moveTimeTask = moveTimeTask;
- tempSpriteP->frameTimeTask = frameTimeTask;
-
- // clear the next and prev fields, just in case
- tempSpriteP->nextSpriteP = NULL;
- tempSpriteP->prevSpriteP = NULL;
-
- // copy the frame array
- for (frame = 0; frame < tempSpriteP->maxFrames; frame++)
- {
- tempSpriteP->frameArray[frame] = cloneSpriteP->frameArray[frame];
- }
-
- *newSpriteP = tempSpriteP;
- }
-
- return err;
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWDisposeSprite
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWDisposeSprite(
- SpritePtr deadSpriteP,
- Boolean disposeFrames)
- {
- SWCloseSprite(deadSpriteP, disposeFrames);
-
- DisposePtr((Ptr)deadSpriteP);
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWCloseSprite
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWCloseSprite(
- SpritePtr deadSpriteP,
- Boolean disposeFrames)
- {
- short frame;
-
- if (deadSpriteP != NULL)
- {
- // remove the sprite time tasks from the time manager queue
- RmvTime((QElemPtr)&deadSpriteP->moveTimeTask);
- RmvTime((QElemPtr)&deadSpriteP->frameTimeTask);
-
- if (disposeFrames)
- {
- for (frame = 0; frame < deadSpriteP->numFrames; frame++)
- {
- SWDisposeFrame(deadSpriteP->frameArray[frame]);
- }
- }
-
- DisposePtr((Ptr)deadSpriteP->frameArray);
- }
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWLockSprite
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWLockSprite(
- SpritePtr srcSpriteP)
- {
- register long numFrames;
-
- // is the sprite not locked?
- numFrames = srcSpriteP->numFrames;
-
- while (numFrames--)
- {
- SWLockFrame(srcSpriteP->frameArray[numFrames]);
- }
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWUnlockSprite
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWUnlockSprite(
- SpritePtr srcSpriteP)
- {
- register long numFrames;
-
- // is the sprite locked?
- numFrames = srcSpriteP->numFrames;
-
- while (numFrames--)
- {
- SWUnlockFrame(srcSpriteP->frameArray[numFrames]);
- }
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWSetSpriteDrawProc
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWSetSpriteDrawProc(
- SpritePtr srcSpriteP,
- DrawProcPtr drawProc)
- {
- srcSpriteP->frameDrawProc = drawProc;
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWStdDrawProc
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWStdDrawProc(
- FramePtr srcFrameP,
- FramePtr dstFrameP,
- Rect* srcRect,
- Rect* dstRect)
- {
- // by the way, CopyBits with a mask region is 60% faster than CopyMask!
- CopyBits((BitMapPtr)srcFrameP->framePix.pixMapP, (BitMapPtr)dstFrameP->framePix.pixMapP,
- srcRect, dstRect, srcCopy, srcFrameP->maskRgn);
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWStdMaskDrawProc
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWStdMaskDrawProc(
- FramePtr srcFrameP,
- FramePtr dstFrameP,
- Rect* srcRect,
- Rect* dstRect,
- RgnHandle maskRgn)
- {
- // by the way, CopyBits with a mask region is 60% faster than CopyMask!
- CopyBits((BitMapPtr)srcFrameP->framePix.pixMapP, (BitMapPtr)dstFrameP->framePix.pixMapP,
- srcRect, dstRect, srcCopy, maskRgn);
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWAddFrame
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL OSErr SWAddFrame(
- SpritePtr srcSpriteP,
- FramePtr newFrameP)
- {
- OSErr err = noErr;
-
- // don’t exceed maximum number of frames
- if (srcSpriteP->numFrames < srcSpriteP->maxFrames)
- {
- srcSpriteP->frameArray[srcSpriteP->numFrames] = newFrameP;
-
- // increment the number of frames
- srcSpriteP->numFrames++;
-
- SWSetCurrentFrame(srcSpriteP, srcSpriteP->frameArray[0]);
- }
- else
- {
- err = kMaxFramesErr;
- }
-
- return err;
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWRemoveFrame
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWRemoveFrame(
- SpritePtr srcSpriteP,
- FramePtr oldFrameP)
- {
- register long numFrames;
- register FramePtr *frameArray;
-
- numFrames = srcSpriteP->numFrames;
- frameArray = srcSpriteP->frameArray;
-
- // find the frame to be removed
- while (numFrames--)
- {
- if (frameArray[numFrames] == oldFrameP)
- {
- // move the rest of the frames down
- while (numFrames < (srcSpriteP->numFrames - 1L))
- {
- frameArray[numFrames] = frameArray[numFrames + 1L];
-
- numFrames++;
- }
-
- break;
- }
- }
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWSetCurrentFrame
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWSetCurrentFrame(
- SpritePtr srcSpriteP,
- FramePtr newFrameP)
- {
- Rect lastRect, rgnRect;
- short horizOffset, vertOffset;
-
- if (srcSpriteP->curFrameP != newFrameP)
- {
- srcSpriteP->curFrameP = newFrameP;
-
- lastRect = srcSpriteP->destFrameRect;
-
- srcSpriteP->destFrameRect = newFrameP->frameRect;
-
- horizOffset = (lastRect.left - srcSpriteP->destFrameRect.left);
- vertOffset = (lastRect.top - srcSpriteP->destFrameRect.top);
-
- srcSpriteP->destFrameRect.left += horizOffset;
- srcSpriteP->destFrameRect.right += horizOffset;
- srcSpriteP->destFrameRect.top += vertOffset;
- srcSpriteP->destFrameRect.bottom += vertOffset;
-
- srcSpriteP->needsToBeDrawn = true;
- }
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWSetCurrentFrameIndex
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWSetCurrentFrameIndex(
- SpritePtr srcSpriteP,
- short frameIndex)
- {
- register FramePtr newFrameP;
- Rect lastRect, rgnRect;
- short horizOffset, vertOffset;
-
- if (frameIndex < srcSpriteP->numFrames)
- {
- newFrameP = srcSpriteP->frameArray[frameIndex];
-
- srcSpriteP->curFrameP = newFrameP;
-
- lastRect = srcSpriteP->destFrameRect;
-
- srcSpriteP->destFrameRect = newFrameP->frameRect;
-
- horizOffset = (lastRect.left - srcSpriteP->destFrameRect.left);
- vertOffset = (lastRect.top - srcSpriteP->destFrameRect.top);
-
- srcSpriteP->destFrameRect.left += horizOffset;
- srcSpriteP->destFrameRect.right += horizOffset;
- srcSpriteP->destFrameRect.top += vertOffset;
- srcSpriteP->destFrameRect.bottom += vertOffset;
-
- srcSpriteP->needsToBeDrawn = true;
- }
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWSetSpriteFrameAdvance
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWSetSpriteFrameAdvance(
- SpritePtr srcSpriteP,
- short frameAdvance)
- {
- srcSpriteP->frameAdvance = frameAdvance;
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWSetSpriteFrameRange
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWSetSpriteFrameRange(
- SpritePtr srcSpriteP,
- short firstFrameIndex,
- short lastFrameIndex)
- {
- srcSpriteP->firstFrameIndex = firstFrameIndex;
- srcSpriteP->lastFrameIndex = lastFrameIndex;
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWSetSpriteFrameTime
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWSetSpriteFrameTime(
- SpritePtr srcSpriteP,
- long timeInterval)
- {
- srcSpriteP->frameTimeInterval = timeInterval;
-
- // is the time interval positive?
- if (timeInterval > 0)
- {
- // if the task is not already primed…
- if (!SWIsTaskPrimed(&srcSpriteP->frameTimeTask.timeTask))
- {
- // …prime it
- srcSpriteP->frameTimeTask.hasTaskFired = true;
- }
- }
- // is the time interval negative?
- else if (timeInterval < 0)
- {
- // if the task is primed…
- if (SWIsTaskPrimed(&srcSpriteP->frameTimeTask.timeTask))
- {
- // …remove it
- RmvTime((QElemPtr)&srcSpriteP->frameTimeTask);
- InsTime((QElemPtr)&srcSpriteP->frameTimeTask);
- }
-
- // the timeInterval is negative, which means never change the frame
- srcSpriteP->frameTimeTask.hasTaskFired = false;
- }
- // is the time interval zero?
- else
- {
- // this means change frames as quickly as possible
- srcSpriteP->frameTimeTask.hasTaskFired = true;
- }
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWSetSpriteFrameProc
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWSetSpriteFrameProc(
- SpritePtr srcSpriteP,
- FrameProcPtr frameProc)
- {
- srcSpriteP->frameChangeProc = frameProc;
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWMoveSprite
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWMoveSprite(
- SpritePtr srcSpriteP,
- short horizLoc,
- short vertLoc)
- {
- if ((horizLoc != 0) || (vertLoc != 0))
- {
- srcSpriteP->destFrameRect.bottom = vertLoc + (srcSpriteP->destFrameRect.bottom -
- srcSpriteP->destFrameRect.top);
- srcSpriteP->destFrameRect.right = horizLoc + (srcSpriteP->destFrameRect.right -
- srcSpriteP->destFrameRect.left);
- srcSpriteP->destFrameRect.top = vertLoc;
- srcSpriteP->destFrameRect.left = horizLoc;
-
- srcSpriteP->needsToBeDrawn = true;
- }
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWOffsetSprite
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWOffsetSprite(
- SpritePtr srcSpriteP,
- short horizDelta,
- short vertDelta)
- {
- if ((horizDelta != 0) || (vertDelta != 0))
- {
- srcSpriteP->destFrameRect.right += horizDelta;
- srcSpriteP->destFrameRect.bottom += vertDelta;
- srcSpriteP->destFrameRect.left += horizDelta;
- srcSpriteP->destFrameRect.top += vertDelta;
-
- srcSpriteP->needsToBeDrawn = true;
- }
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWSetSpriteLocation
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWSetSpriteLocation(
- SpritePtr srcSpriteP,
- short horizLoc,
- short vertLoc)
- {
- srcSpriteP->destFrameRect.bottom = vertLoc + (srcSpriteP->destFrameRect.bottom -
- srcSpriteP->destFrameRect.top);
- srcSpriteP->destFrameRect.right = horizLoc + (srcSpriteP->destFrameRect.right -
- srcSpriteP->destFrameRect.left);
- srcSpriteP->destFrameRect.top = vertLoc;
- srcSpriteP->destFrameRect.left = horizLoc;
-
- srcSpriteP->deltaFrameRect = srcSpriteP->destFrameRect;
- srcSpriteP->oldFrameRect = srcSpriteP->destFrameRect;
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWSetSpriteMoveBounds
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWSetSpriteMoveBounds(
- SpritePtr srcSpriteP,
- Rect* moveBoundsRect)
- {
- srcSpriteP->moveBoundsRect = *moveBoundsRect;
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWSetSpriteMoveDelta
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWSetSpriteMoveDelta(
- SpritePtr srcSpriteP,
- short horizDelta,
- short vertDelta)
- {
- // set sprite’s velocity
- srcSpriteP->horizMoveDelta = horizDelta;
- srcSpriteP->vertMoveDelta = vertDelta;
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWSetSpriteMoveTime
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWSetSpriteMoveTime(
- SpritePtr srcSpriteP,
- long timeInterval)
- {
- srcSpriteP->moveTimeInterval = timeInterval;
-
- // is the time interval positive?
- if (timeInterval > 0)
- {
- // if the task is not already primed…
- if (!SWIsTaskPrimed(&srcSpriteP->moveTimeTask.timeTask))
- {
- // …prime it
- srcSpriteP->moveTimeTask.hasTaskFired = true;
- }
- }
- // is the time interval negative?
- else if (timeInterval < 0)
- {
- // if the task is primed…
- if (SWIsTaskPrimed(&srcSpriteP->moveTimeTask.timeTask))
- {
- // …remove it
- RmvTime((QElemPtr)&srcSpriteP->moveTimeTask);
- InsTime((QElemPtr)&srcSpriteP->moveTimeTask);
- }
-
- // the timeInterval is negative, which means never change the frame
- srcSpriteP->moveTimeTask.hasTaskFired = false;
- }
- // is the time interval zero?
- else
- {
- // this means change frames as quickly as possible
- srcSpriteP->moveTimeTask.hasTaskFired = true;
- }
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWSetSpriteMoveProc
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWSetSpriteMoveProc(
- SpritePtr srcSpriteP,
- MoveProcPtr moveProc)
- {
- srcSpriteP->spriteMoveProc = moveProc;
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWBounceSpriteMoveProc
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWBounceSpriteMoveProc(
- SpritePtr srcSpriteP,
- Point* spritePoint)
- {
- if (srcSpriteP->destFrameRect.left < srcSpriteP->moveBoundsRect.left)
- {
- srcSpriteP->horizMoveDelta = -srcSpriteP->horizMoveDelta;
- spritePoint->h = srcSpriteP->moveBoundsRect.left;
- }
- else if (srcSpriteP->destFrameRect.right > srcSpriteP->moveBoundsRect.right)
- {
- srcSpriteP->horizMoveDelta = -srcSpriteP->horizMoveDelta;
- spritePoint->h = srcSpriteP->moveBoundsRect.right -
- (srcSpriteP->curFrameP->frameRect.right - srcSpriteP->curFrameP->frameRect.left);
- }
-
- if (srcSpriteP->destFrameRect.top < srcSpriteP->moveBoundsRect.top)
- {
- srcSpriteP->vertMoveDelta = -srcSpriteP->vertMoveDelta;
- spritePoint->v = srcSpriteP->moveBoundsRect.top;
- }
- else if (srcSpriteP->destFrameRect.bottom > srcSpriteP->moveBoundsRect.bottom)
- {
- srcSpriteP->vertMoveDelta = -srcSpriteP->vertMoveDelta;
- spritePoint->v = srcSpriteP->moveBoundsRect.bottom -
- (srcSpriteP->curFrameP->frameRect.bottom - srcSpriteP->curFrameP->frameRect.top);
- }
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWWrapSpriteMoveProc
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWWrapSpriteMoveProc(
- SpritePtr srcSpriteP,
- Point* spritePoint)
- {
- Point oldSpritePoint = *spritePoint;
-
- if (srcSpriteP->destFrameRect.left > srcSpriteP->moveBoundsRect.right)
- {
- spritePoint->h = srcSpriteP->moveBoundsRect.left -
- (srcSpriteP->destFrameRect.right -
- srcSpriteP->destFrameRect.left);
- }
- else if (srcSpriteP->destFrameRect.right < srcSpriteP->moveBoundsRect.left)
- {
- spritePoint->h = srcSpriteP->moveBoundsRect.right;
- }
-
- if (srcSpriteP->destFrameRect.top > srcSpriteP->moveBoundsRect.bottom)
- {
- spritePoint->v = srcSpriteP->moveBoundsRect.top -
- (srcSpriteP->destFrameRect.bottom -
- srcSpriteP->destFrameRect.top);
- }
- else if (srcSpriteP->destFrameRect.bottom < srcSpriteP->moveBoundsRect.top)
- {
- spritePoint->v = srcSpriteP->moveBoundsRect.bottom;
- }
-
- if ((spritePoint->h != oldSpritePoint.h) || (spritePoint->v != oldSpritePoint.v))
- {
- SWSetSpriteLocation(srcSpriteP, spritePoint->h, spritePoint->v);
- }
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWSetSpriteCollideProc
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWSetSpriteCollideProc(
- SpritePtr srcSpriteP,
- CollideProcPtr collideProc)
- {
- srcSpriteP->spriteCollideProc = collideProc;
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWSetSpriteVisible
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWSetSpriteVisible(
- SpritePtr srcSpriteP,
- Boolean isVisible)
- {
- srcSpriteP->isVisible = isVisible;
- srcSpriteP->needsToBeDrawn = true;
- srcSpriteP->needsToBeErased = !isVisible;
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWIsSpriteInRect
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL Boolean SWIsSpriteInRect(
- SpritePtr srcSpriteP,
- Rect* testRect)
- {
- return (!((srcSpriteP->destFrameRect.top >= testRect->bottom) ||
- (srcSpriteP->destFrameRect.bottom <= testRect->top) ||
- (srcSpriteP->destFrameRect.left >= testRect->right) ||
- (srcSpriteP->destFrameRect.right <= testRect->left)));
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWTimeTask
- ///--------------------------------------------------------------------------------------
-
- #ifndef THINK_C
-
- TimeTaskPtr SWGetTimeTask(void) = 0x2009; // move.l A1, D0
-
- #endif
-
- pascal void SWTimeTask(void)
- {
- // on entry a pointer to our time task is in A1
-
- #ifdef THINK_C
-
- // THINK C’s inline assembly is very convenient
- asm
- {
- move.b #true, TimeTaskRec.hasTaskFired(A1)
- }
-
- #else
-
- // but, this might be compiled with
- // MPW C, Symantec C++ for MPW, or THINK C++
- // which don’t support inline assembly!!!
- SWGetTimeTask()->hasTaskFired = true;
-
- #endif
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWIsTaskPrimed
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL Boolean SWIsTaskPrimed(
- TMTask* tmTaskP)
- {
- return (tmTaskP->qType & 0x8000) != 0;
- }
-
-